package de.baumann.browser.activitys.oc

import android.content.Context
import android.content.Intent
import de.baumann.browser.R
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IBaseView
import de.baumann.browser.utils.BitmapUtil
import de.baumann.browser.utils.QrCodeUtil
import de.baumann.browser.utils.StringUtil
import kotlinx.android.synthetic.main.activity_collect_money.*
import kotlinx.android.synthetic.main.include_tool_bar.*

class CollectMoneyActivity : BaseOdinActivity<IBaseView, BasePresenter<IBaseView>>() {

    companion object {
        fun startCollectMoneyActivity(context: Context, address: String, cn: String = "ODIN") {
            context.startActivity(Intent(context, CollectMoneyActivity::class.java).apply {
                putExtra("address", address)
                putExtra("cn", cn)
            })
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_collect_money
    }

    override fun getTitleText(): String {
//        return "ODIN收款"
        return "${intent.getStringExtra("cn")}收款"
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        var address = getAddress()
        if (address.startsWith("0")) {
            address = "od${address.substring(1)}"
        }
        tvCollectAddress.text = address
        tvAddressCopy.setOnClickListener {
            StringUtil.copy(mContext, address)
            showShortToast("收款地址已复制到剪切板")
        }

        smzr.text = "扫二维码，转入${intent.getStringExtra("cn")}"
    }

    override fun initData() {
        var address = getAddress()
        if (address.startsWith("0")) {
            address = "od${address.substring(1)}"
        }
        ivCollect.setImageBitmap(QrCodeUtil.createCode(address, 400, 400))
    }

    override fun createPresenter(): BasePresenter<IBaseView>? {
        return null
    }

    override fun createView(): IBaseView? {
        return null
    }

    private fun getAddress(): String {
        return intent.getStringExtra("address")
    }

    override fun showBindEth(): Boolean {
        return false
    }

}
